package cn.edu.ncu.housinghub.controller.admin;

import cn.edu.ncu.housinghub.dto.request.admin.AdminLoginRequest;
import cn.edu.ncu.housinghub.service.AdminService;
import cn.edu.ncu.housinghub.vo.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(@Valid @RequestBody AdminLoginRequest loginRequest) {
        System.out.println("🔍 管理员登录请求 - 用户名: " + loginRequest.getUsername() + ", 密码: " + loginRequest.getPassword());
        return adminService.login(loginRequest.getUsername(), loginRequest.getPassword());
    }

    /**
     * 管理员登出
     * @param info 管理员token
     * @return 登出结果
     */
    @PostMapping("/logout")
    public Result logout(@RequestHeader("info") String info) {
        adminService.logout(info);
        return Result.success("登出成功");
    }
}
